import React, { Component } from 'react';
import './Order.css'
import OrderList from '../../components/Orderlist'
// import axios from 'axios'
// import { findDOMNode } from 'react-dom';
// import ReactSwipe from 'react-swipes'


class Order extends Component {
    constructor() {
        super()
        this.state = {
            orderList: [],
        }
    }
    componentWillMount() {
        this.axios({
            url: 'api1/olife/prder/query',//不用引入，直接在api后面接接口
            method: 'get',
            params: {
                user_id: '1'
            }
        }).then(data => {
            // console.log(data.data.data);
            console.log(data.data.data)
            if (data.data.code === 200) {
                this.setState({
                    orderList: data.data.data
                })
            }
        }).catch(err => {
            console.log(err)
        })





    }
    // 数组对象根据某个字段去重，参数传数组和对应的字段
    // unique(arr,val) {
    //     const res = new Map();
    //     return arr.filter(item => !res.has(item[val]) && res.set(item[val], 1))
    // }

    handlerDatas(arr) {
        let obj = {};
        arr.forEach((item, index) => {
            let { order_id } = item;
            if (!obj[order_id]) {
                obj[order_id] = {
                    order_id,
                    children: []
                }
            }
            obj[order_id].children.push(item);
        });
        console.log(Object.values(obj));
        return Object.values(obj); // 最终输出
    }
    render() {
        return (
            <div className='mydiv'>
                <div className='ws_header'>
                    <p>全部订单</p>
                </div>
                <div className='ws_content'>
                    <OrderList data={this.state.orderList}></OrderList>

                    {/* <div className='content'>
                        <div className='content_header'>
                            <div className='storename'>
                                <div className='img'><img src="../../../logo512.png" alt=""/></div>
                                <div>
                                    <div><span>肯德基宅急送(吉泰路店)</span></div>
                                    <div className='activity'><span>99减10</span></div>
                                </div>
                                <div><span className='iconfont icon-iconfontyoujiantou-zuo'></span></div>
                            </div>
                            <div><span>已取消</span></div>
                        </div>
                        <div className='content_order'>
                            <div className='price'>
                                <p>￥35</p>
                                <p>共3件</p>
                            </div>
                            <div  className='content_order1' >
                                <div>
                                    <div className='content_img'><img src="../../../logo512.png" alt=""/></div>
                                    <p>2块新奥尔良鸡翅</p>
                                </div>
                                <div>
                                    <div className='content_img'><img src="../../../logo512.png" alt=""/></div>
                                    <p>2块新奥尔良鸡翅</p>
                                </div>
                                <div>
                                    <div className='content_img'><img src="../../../logo512.png" alt=""/></div>
                                    <p>2块新奥尔良鸡翅</p>
                                </div>
                                <div>
                                    <div className='content_img'><img src="../../../logo512.png" alt=""/></div>
                                    <p>2块新奥尔良鸡翅</p>
                                </div>
                                <div>
                                    <div className='content_img'><img src="../../../logo512.png" alt=""/></div>
                                    <p>2块新奥尔良鸡翅</p>
                                </div>
                                <div>
                                <div className='kongbai'></div>
                                </div>
                            </div>
                            
                            

                        </div>
                        <div className='content_evaluation'>
                            <div><span onClick>再来一单</span></div>
                            <div><span>去评价</span></div>
                        </div>
                    </div> */}




                </div>

            </div>
        );
    }
}

export default Order;